package young.frame;

import young.Util.DBUtil;
import young.pojo.UserDO;
import young.service.UserService;
import young.service.impl.UserServiceImpl;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 存储功能
 */

public class Save extends JPanel implements ActionListener {
    private Atm frame;

    private JButton returnBut;
    private JTextField saveMoney;
    private JButton confirm;


    public Save(Atm frame) {


        this.frame = frame;
        //空布局
        this.setLayout(null);
        //设置透明
        this.setOpaque(false);

        confirm = new JButton("确定");
        confirm.setBounds(350, 500, 100, 50);
        this.add(confirm);
        confirm.addActionListener(this);

        //返回按钮,返回菜单界面
        returnBut = new JButton("返回");
        returnBut.setBounds(350, 600, 100, 50);
        this.add(returnBut);
        returnBut.addActionListener(this);


        saveMoney = new JTextField(); //存款文本框
        saveMoney.setBounds(320, 220, 100, 30);
        this.add(saveMoney);
        saveMoney.addActionListener(this);

        JLabel label = new JLabel("存款：");//存款标签
        label.setBounds(280, 220, 80, 30);
        this.add(label);

    }

    @Override
    public void actionPerformed(ActionEvent e) {

        UserService service=new UserServiceImpl();

        if (e.getSource() == returnBut) {
            frame.switchPanel("菜单");
        } else if (e.getSource() == confirm) {
           String id=frame.getLoginUser().getId();//获取登陆ID
            int save= Integer.parseInt(saveMoney.getText()); //获取存入金额

            service.saveMoney(id,save); //存入业务

            JOptionPane.showMessageDialog(this, "存入成功");
//
        }
    }

    public void setBlance(double blance) {

    }


    public JTextField getSaveMoney() {
        return saveMoney;
    }

    public void setSaveMoney(JTextField saveMoney) {
        this.saveMoney = saveMoney;
    }

}